package com.ruoyi.project.digital.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.project.digital.domain.dto.PetAnnexDto;
import com.ruoyi.project.digital.service.IPetService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.digital.domain.PetAnnex;
import com.ruoyi.project.digital.service.IPetAnnexService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 宠物附件Controller
 *
 * @author ruoyi
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/digital/petAnnex")
public class PetAnnexController extends BaseController
{
    @Autowired
    private IPetAnnexService petAnnexService;
    @Autowired
    private IPetService petService;

    /**
     * 查询宠物附件列表
     */
    @PreAuthorize("@ss.hasPermi('digital:petAnnex:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetAnnex petAnnex)
    {
        startPage();
        List<PetAnnex> list = petAnnexService.selectPetAnnexList(petAnnex);
        return getDataTable(list);
    }

    @GetMapping("/listall")
    public AjaxResult listall(PetAnnex petAnnex)
    {
        List<PetAnnex> list = petAnnexService.selectPetAnnexList(petAnnex);
        return AjaxResult.success(list);
    }

    /**
     * 导出宠物附件列表
     */
    @PreAuthorize("@ss.hasPermi('digital:petAnnex:export')")
    @Log(title = "宠物附件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PetAnnex petAnnex)
    {
        List<PetAnnex> list = petAnnexService.selectPetAnnexList(petAnnex);
        ExcelUtil<PetAnnex> util = new ExcelUtil<PetAnnex>(PetAnnex.class);
        return util.exportExcel(list, "petAnnex");
    }

    /**
     * 获取宠物附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('digital:petAnnex:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(petAnnexService.selectPetAnnexById(id));
    }

    @GetMapping(value = "getPet/{id}")
    public AjaxResult getPet(@PathVariable("id") Long id)
    {
        PetAnnex petAnnex=new PetAnnex();
        petAnnex.setPetId(id);
        return AjaxResult.success(petAnnexService.selectPetAnnexList(petAnnex));
    }

    /**
     * 新增宠物附件
     */
    @PreAuthorize("@ss.hasPermi('digital:petAnnex:add')")
    @Log(title = "宠物附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetAnnex petAnnex)
    {
        return toAjax(petAnnexService.insertPetAnnex(petAnnex));
    }

    /**
     * 修改宠物附件
     */
    @PreAuthorize("@ss.hasPermi('digital:petAnnex:edit')")
    @Log(title = "宠物附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetAnnex petAnnex)
    {
        return toAjax(petAnnexService.updatePetAnnex(petAnnex));
    }

    /**
     * 删除宠物附件
     */
    @PreAuthorize("@ss.hasPermi('digital:petAnnex:remove')")
    @Log(title = "宠物附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(petAnnexService.deletePetAnnexByIds(ids));
    }
}
